package com.micangcaihang.common.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.TextView;

import com.micangcaihang.common.R;


/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayonggmail@gmail.com
 *     time   : 2017/03/11
 *     desc   : 加载动画dialog
 *     version: 1.0
 * </pre>
 */

public class LoadingDialog extends Dialog {
    private TextView tvMessage;
    private Context context;
    /**
     * 下方显示message
     */
    private String message;

    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.LoadingDialog);
        this.context = context;
    }

    public LoadingDialog(Context context, String message) {
        super(context, R.style.LoadingDialog);
        this.context = context;
        this.message = message;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.loading_layout);
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
        tvMessage = (TextView) findViewById(R.id.tv_loading_msg);
        if (message != null) {
            tvMessage.setText(message);
        }
    }



    public void show(String message) {
        this.message = message;
        if (tvMessage != null && message != null) {
            tvMessage.setText(message);
        }
        super.show();
    }

    public void show(int msgResId) {
        show(getContext().getString(msgResId));
    }

}
